
from openai import OpenAI
import os
base_url = os.environ.get("OPENAI_BASE_URL", "http://127.0.0.1:9000/v1")
api_key = "xxxx"
########################### ###########################
client = OpenAI(base_url=base_url, api_key=api_key)


response = client.chat.completions.create(
    model="glm-4v-9b",
    messages=[
        {
            "role": "user",
            "content": "你好",
        }
    ],
    # messages=[
    #     {
    #         "role": "user",
    #         "content": [
    #                 {
    #                     "type": "image_url",
    #                     "image_url": {
    #                         "url": "https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen-VL/assets/demo.jpeg"
    #                     },
    #                 },
    #             {"type": "text", "text": "描述这个图片"},
    #         ],
    #     }
    # ],
    max_tokens=128,
    temperature=0.0,
    stream=True
)

for chunk in response:
    print(chunk.choices[0].delta.content, end="", flush=True)
